import ora from "ora";
import { App } from "../../types/app";
import { runHook } from "../hook";
import { compressFiles } from "../setup/compressFiles";
import { groupFiles } from "../setup/groupFiles";
import { uploadZipFolder } from "../setup/uploadZipFolder";
import { createTempFileDir } from "../../utils/common";

export async function initApp(app: App) {
    const { plugins, use, spinner } = app;

    spinner.start("Initializing application...");

    for (const plugin of plugins) {
        await use(plugin);
        spinner.text = `Loaded plugin: ${plugin.name}`; // 更新加载信息
    }
    spinner.succeed("All plugins loaded successfully.");

    createTempFileDir();

    // spinner.start("Grouping files...");
    // groupFiles(app);
    // spinner.succeed("Files grouped successfully.");
    // await runHook("groupFiles");

    spinner.start("Compressing files...");
    await compressFiles(app);
    spinner.succeed("Files compressed successfully.");
    await runHook("compressFiles");

    spinner.start("Uploading zip folder...");
    await uploadZipFolder(app);
    spinner.succeed("Zip folder uploaded successfully.");
    await runHook("uploadZipFolder");
}
